//
//  TestViewController.m
//  11-16
//
//  Created by mac on 15-11-16.
//  Copyright (c) 2015年 ztt. All rights reserved.
//

#import "TestViewController.h"
#import "ViewController.h"
@interface TestViewController ()
{
    NSArray * data;
    NSArray * number;
    NSArray * header;
}
@end

@implementation TestViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.title = @"第二个控制器";
    data = @[
                @[@"爱人",@"爱情"],
                @[@"白色",@"百合"],
                @[@"曹操",@"曹植"],
                @[@"德玛",@"德邦"],
                @[@"尔康",@"二胎"]
             ];
    number = @[
                @"13838380438",
                @"29861298658",
                @"38946516135",
                @"45168469146",
                @"58465431651"
               ];
    header = @[
                @"A",
                @"B",
                @"C",
                @"D",
                @"E"
               ];
    //导航栏显示编辑状态，出来删除
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return data.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [data[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    
    cell.textLabel.text = data[indexPath.section][indexPath.row];
    cell.detailTextLabel.text = number[indexPath.row];
    //cell.textLabel.text = header[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return header[section];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //实现点击渐变
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    //下一个界面
    ViewController * con = [ViewController new];
    [self.navigationController pushViewController:con animated:YES];
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{
    return YES;//删除
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
    //移动
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    //删除
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        NSMutableArray * arr = data.mutableCopy;
        [arr removeObjectAtIndex:indexPath.row];
        data = arr;
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
